/* $Id: JMapGridUnitTest.java 63 2010-02-14 13:52:34Z aaron.day $ */
package org.crazydays.gameplan.map.swing;


import java.awt.Dimension;
import java.awt.Graphics;

import org.junit.*;
import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.map.Geometry;
import org.crazydays.gameplan.map.GridType;

/**
 * JMapGridUnitTest
 */
public class JMapGridUnitTest
{
    /**
     * Test constructor.
     */
    @Test
    public void testConstructor_square()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // test
        JMapGrid component = new JMapGrid(geometry);

        // verify
        assertEquals("height", 480, component.getHeight());
        assertEquals("width", 640, component.getWidth());
        assertNotNull("grid", component.grid);
    }

    /**
     * Test constructor.
     */
    @Test
    public void testConstructor_hexagon()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.HEXAGON, 20);

        // test
        JMapGrid component = new JMapGrid(geometry);

        // verify
        assertEquals("height", 480, component.getHeight());
        assertEquals("width", 640, component.getWidth());
        assertNotNull("grid", component.grid);
    }

    /**
     * Test constructor.
     */
    @Test
    public void testConstructor_isometric()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.ISOMETRIC, 20);

        // test
        JMapGrid component = new JMapGrid(geometry);

        // verify
        assertEquals("height", 480, component.getHeight());
        assertEquals("width", 640, component.getWidth());
        assertNotNull("grid", component.grid);
    }

    /**
     * Test getPreferredSize().
     */
    @Test
    public void testGetPreferredSize()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // setup
        JMapGrid component = new JMapGrid(geometry);

        // test
        Dimension result = component.getPreferredSize();

        // verify
        assertEquals("height", 480, result.getHeight(), .0001);
        assertEquals("width", 640, result.getWidth(), .0001);
    }

    /**
     * Test getPaint(Graphics).
     */
    @Test
    public void testPaint()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // mocks
        Graphics graphics = createMock(Graphics.class);

        // setup
        JMapGrid component = new JMapGrid(geometry);

        // expect
        expect(graphics.drawImage(component.grid, 0, 0, null)).andReturn(true);

        // replay
        replay(graphics);

        // test
        component.paint(graphics);

        // verify
        verify(graphics);
    }
}
